package com.ps.service;

import com.ps.model.vo.statictis.FourBlockStat;
import com.ps.mapper.StatisticMapper;
import com.ps.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
@Slf4j
public class StatisticService {
    @Resource
    private StatisticMapper mapper;

    //获取 今日采购额、今日销售额、今日毛利润
    public FourBlockStat getFourBlock() {
        long now = DateUtil.getTimestampNow();

        FourBlockStat stat = new FourBlockStat();

        BigDecimal purchase = mapper.getPurchaseOrderDailyTotalPurchasePrice(now, null);
        BigDecimal sell = mapper.getSellOrderDailyTotalPurchasePrice(now, null);

        stat.setPurchase(purchase);
        stat.setSell(sell);
        stat.setProfit(sell.subtract(purchase));

        return stat;
    }
}
